package com.zitangkou.user.domain.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zitangkou.user.domain.IRoleDomainService;
import com.zitangkou.user.domain.RoleDomain;
import com.zitangkou.user.domain.converter.IRoleDomainConverter;
import com.zitangkou.user.entity.RoleDo;
import com.zitangkou.common.enums.StatusEnum;
import com.zitangkou.user.mapper.RoleMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Deng Ningning
 * @version 1.0
 * @date 2020/11/13 21:59
 */
@Service
public class RoleDomainServiceImpl extends ServiceImpl<RoleMapper, RoleDo> implements IRoleDomainService {

    @Resource
    private RoleMapper roleMapper;

    @Resource
    private IRoleDomainConverter roleDomainConverter;

    @Override
    public IPage<RoleDomain> selectPageByConditions(Integer current, Integer size, String keyword, StatusEnum status) {
        IPage<RoleDo> page = new Page<>(current, size);
        page = roleMapper.selectPageByConditions(page, StringUtils.trimToEmpty(keyword), status);
        return new Page<RoleDomain>()
                .setRecords(roleDomainConverter.toDomainList(page.getRecords()))
                .setTotal(page.getTotal());
    }

    @Override
    public RoleDomain getRoleById(String roleId) {
        return roleDomainConverter.toDomain(roleMapper.selectById(roleId));
    }
}
